<?php
	session_start();
	if(!isset($_SESSION['username'])):
		header("Location: login.php");
	endif;	
?>

<!DOCTYPE html>
<html>
<head>
	<script src="global.js"></script>
	<link href="style.css" rel="Stylesheet" type="text/css" />
</head>
<body onload="initialize();">

	<div id="welcomeMessageToUser" class="WebsiteBanner">Please return to the <a href="login.php">Login Page</a> and login.</div><br/>
	<div id="messagePanel"></div>
	<div id="userNavBar" style="display:none;" class="NavigationBar">
		<input type="button" onclick="renderTicketCreationPage();" value="Submit New Ticket">
		<input type="button" onclick="renderUserTicketsPage();" name="renderUserTickets" value="See My (User) Tickets">
		<input type="button" onclick="renderChangePasswordPage();" value="Change Password">
		<input type="button" onclick="logoutCurrentUser();" name="logout" value="Log Out">
	</div>
	<div id="adminNavBar" style="display:none;" class="NavigationBar">		
		<input type="button" onclick="renderTicketCreationPage();" value="Submit New Ticket">
		<input type="button" onclick="getTicketsFromServerAndCreateTicketsTable();" value="Admin Page">
		<input type="button" onclick="renderChangePasswordPage();" value="Change Password">
		<input type="button" onclick="logoutCurrentUser();" name="logout" value="Log Out">
	</div>
	<div id="ticketPage" style="display:none;">
		<div class="PostContainer">	
			<div class="Post">
				<div class="PostHeader">
					Viewing Tickets
				</div>
				<div class="PostContent">					
					<table id="adminTable" class="SiteTable" width="700" border="1" align="center" cellpadding="2" cellspacing="1" bgcolor="#EEE">
						<tr>
							<th>
								Ticket #
							</th>
							<th>
								Received
							</th>
							<th>
								Sender Name
							</th>
							<th>
								Sender Email
							</th>
							<th>
								Subject
							</th>
							<th>
								Tech
							</th>
							<th>
								Status
							</th>
							<th>
								Select
							</th>
						</tr>
						<tr>
							<td>Sort by <input checked onclick="updateSortColumn('ticketID');" type='radio' name='selectedSort' ></td>
							<td>Sort by <input onclick="updateSortColumn('received');" type='radio' name='selectedSort' ></td>
							<td>Sort by <input onclick="updateSortColumn('senderName');" type='radio' name='selectedSort' ></td>
							<td>Sort by <input onclick="updateSortColumn('senderEmail');" type='radio' name='selectedSort' ></td>
							<td>Sort by <input onclick="updateSortColumn('subject');" type='radio' name='selectedSort' ></td>
							<td>Sort by <input onclick="updateSortColumn('admin');" type='radio' name='selectedSort' ></td>
							<td>Sort by <input onclick="updateSortColumn('status');" type='radio' name='selectedSort' ></td>
						</tr>
					</table>
				</div>
			</div>
		</div>
		<div id="adminViewTicketOptions" class="NavigationBar">
			<input type="button" style="display:none;" onclick="updateButtonMode('ViewAllTickets');" id="ViewAllTickets" value="View All Tickets">			
			<input type="button" onclick="updateButtonMode('ViewAdminTickets');" id="ViewAdminTickets" value="View My (Admin) Tickets">
			<input type="button" onclick="updateButtonMode('ViewUnassignedTickets');" id="ViewUnassignedTickets" value="View Unassigned Tickets">
			<input type="button" onclick="updateButtonMode('ViewOpenTickets');" id="ViewOpenTickets" value="View Open Tickets">			
			<input type="button" onclick="viewSelectedTicket();" id="ViewSelectedTicket" value="View Selected Ticket">			
		</div>
		<div id="publicButtons" class="NavigationBar">
			<input type="button" onclick="sortTicketsFromButtonPress();" id="SortTickets" value="Sort">			
		</div>
	</div>		
	<div id="ticketCreationPage" style="display:none;">
		<div class="PostContainer">	
			<div class="Post">
				<div class="PostHeader">
					Create New Ticket
				</div>
				<div class="PostContent">					
					<p>First Name: <input type="text" id="ticketCreationFirstName"></p>
					<p>Last Name: <input type="text" id="ticketCreationLastName"></p>
					<p>Email Address: <span id="ticketCreationEmailAddress">[email]</span></p>
					<p>Subject of problem: <input style="width:400px;" type="text" id="ticketCreationSubject"></p>
					<p>
						Brief Description of Problem: <br/> <textarea id="ticketCreationDescription" type="text" rows="6" cols="50"></textarea> <br/>
					</p>
					<p><input type="button" onclick="submitNewTicket();" value="Create New Ticket"></p>
					<div id="ticketCreationMessage"></div>
				</div>
			</div>
		</div>
	</div>
	<div id="singleTicketPage" style="display:none;">
		<div id="singleTicketButtons" class="NavigationBar">
			<input type="button" id="singleTicketCloseTicket" onclick="singleTicketCloseTicket();" value="Close Ticket">
			<input type="button" id="singleTicketReopenTicket" onclick="singleTicketReopenTicket();" value="Re-Open Ticket">
			
			<input type="button" id="singleTicketAssignSelf" onclick="singleTicketAssignSelf();" value="Assign Self to Ticket">
			<input type="button" id="singleTicketRemoveSelf" onclick="singleTicketRemoveSelf();" value="Remove Self from Ticket">
			
			<input type="button" onclick="singleTicketEmailUser();" value="Email User">
			<input type="button" onclick="singleTicketDelete();" value="Delete Ticket">
			<input type="button" onclick="singleTicketFindSubmittersTickets();" value="Find Submitter's Tickets">
			<input type="button" onclick="singleTicketFindSimilarTickets();" value="Find Similar Tickets">
			<input type="button" onclick="getTicketsFromServerAndCreateTicketsTable();" value="Go Back to Admin Page">
		</div>
		<div class="PostContainer">	
			<div class="Post">
				<div class="PostHeader">
					Viewing Single Ticket
				</div>
				<div class="PostContent">
					<table id="singleTicketTable" class="SiteTable" width="700" border="1" align="center" cellpadding="2" cellspacing="1" bgcolor="#EEE">
						<tr>
							<th>
								Ticket #
							</th>
							<th>
								Received
							</th>
							<th>
								Sender Name
							</th>
							<th>
								Sender Email
							</th>
							<th>
								Subject
							</th>
							<th>
								Tech
							</th>
							<th>
								Status
							</th>
						</tr>
					</table>
				</div>
			</div>
		</div>
	</div>
	<div id="emailPage" style="display:none;">
		<div class="PostContainer">	
			<div class="Post">
				<div class="PostHeader">
					Send Email to Ticket Submitter
				</div>
				<div class="PostContent">		
					<p>Sender (admin): <span id="emailPageAdminEmail">[admin email]</span></p>
					<p>Recipient (submitter of ticket): <span id="emailPageSenderEmail">[ticket sender email]</span></p>
					<p>Subject: <input style="width: 400px;" type="text" id="emailPageEmailSubject"></p>
					<p>Message:<br/> <textarea id="emailPageEmailMessage" type="text" rows="6" cols="50"></textarea></p>
					<p><input type="button" onclick="sendEmail();" value="Send Email" ></p>
				</div>
			</div>
		</div>
	</div>
	<div id="changePasswordPage" style="display:none;">
		<div class="PostContainer">	
			<div class="Post">
				<div class="PostHeader">
					Send Email to Ticket Submitter
				</div>
				<div class="PostContent">
					<p>Enter new password: <input style="width: 400px;" type="password" id="newPassword"></p>
					<p><input type="button" onclick="updateUserPassword();" value="Change Password" ></p>
				</div>
			</div>
		</div>
	</div>	

</body>
</html>